#!/usr/bin/env bash

set -o nounset
set -o errexit
set -o pipefail

STARTUP_DIR="$( cd "$( dirname "$0" )" && pwd )"

function do_build {
    local SELDON_CORE_VM_DIR=$1
    eval $(minikube docker-env)
    docker run --rm -it \
        -v /var/run/docker.sock:/var/run/docker.sock \
        -v /home/docker/.m2:/root/.m2 \
        -v ${SELDON_CORE_VM_DIR}:/work \
        seldonio/core-builder:0.1 bash -c 'make -f Makefile.ci build'
}

SELDON_CORE_LOCAL_DIR=${STARTUP_DIR}

UNAME_S=$(uname -s)

SELDON_CORE_VM_DIR=UNKOWN
if [ ${UNAME_S} = "Darwin" ]; then
	SELDON_CORE_VM_DIR=${SELDON_CORE_LOCAL_DIR}
fi
if [ ${UNAME_S} = "Linux" ]; then
	SELDON_CORE_VM_DIR=$(echo ${SELDON_CORE_LOCAL_DIR}|sed -e 's|^/home/|/hosthome/|')
fi

echo "-------------------------------------------------"
echo "Translating paths"
echo "local: ${SELDON_CORE_LOCAL_DIR}"
echo "   vm: ${SELDON_CORE_VM_DIR}"
echo "-------------------------------------------------"
do_build ${SELDON_CORE_VM_DIR}

